#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> state_type;

int main() {
    int object_num, packet_vol, tmp;
    cin >> object_num >> packet_vol;
    vector<int> weights(object_num);
    vector<int> values(object_num);
    for (int i = 0; i < object_num; ++i) {
        cin >> tmp;
        weights[i] = tmp;
        cin >> tmp;
        values[i] = tmp;
        // cout << tmp;
    }

    vector<vector<state_type>> state_matrix(object_num+1, vector<state_type>(packet_vol+1));
    // int ques1, ques2;
    // initial state
    for (int i = 0; i < packet_vol+1; ++i) {
        state_matrix[0][i].first = 0;
        state_matrix[0][i].second = numeric_limits<int>::min();
    }
    for (int i = 0; i < object_num+1; ++i) {
        state_matrix[i][0].first = 0;
        state_matrix[i][0].second = 0;
    }
    for (int i = 1; i < object_num+1; ++i) {
        for (int j = 1; j < packet_vol+1; ++j) {
            int ques1_max = numeric_limits<int>::min();
            int ques2_max = numeric_limits<int>::min();
            for (int k = 0; k < 2; ++k) {
                // question 1
                if (j >= k*weights[i-1]) {
                    ques1_max = max(ques1_max, state_matrix[i-1][j-k*weights[i-1]].first + k*values[i-1]);
                }

                // question 2
                if (j >= k*weights[i-1]) {
                    ques2_max = max(ques2_max, state_matrix[i-1][j-k*weights[i-1]].second + k*values[i-1]);
                }
            }
            state_matrix[i][j].first = ques1_max;
            state_matrix[i][j].second = ques2_max;
        }
    }

    cout << state_matrix[object_num][packet_vol].first << endl;
    cout << (state_matrix[object_num][packet_vol].second < 0 ? 0:state_matrix[object_num][packet_vol].second) << endl;
}